window.onload = function() {
	$("#inventory").change(function() {
		calculationPlanAmount();
	});
	$("#perNum").change(function() {
		calculationPlanAmount();
	});
}

function calculationPlanAmount(){
	var inventory = $("#inventory").val();
	var perNum = $("#perNum").val();
	if(inventory != null && inventory != undefined && inventory != ""){
		if(perNum != null && perNum != undefined && perNum != ""){
			$("#planAmount").val(Number(inventory)*Number(perNum));
		}
	}
}

//页面跳转
function toIndex(){
	var mapfactory = $("#mapfactory").val();
	var mapCode = $("#mapCode").val();
	var mapPage = $("#mapPage").val();
	var url = basePath+"/bus/meter/meterList?modelCode="+mapCode+"&factory="+mapfactory+"&page="+mapPage;
    window.location.href = basePath + '/bus/meter/returnMeterGive?url=' + basePath + '/bus/meter/meterList&flg=queryMeterList';
}

// 获取table每一行数据
function getTableValue(){
	if(checkInput()){
		// 获取计划信息
		var meterResult = [];
				var id = $("#id").val();
				var modelCode= $("#modelCode").val();// 部品番号
				var useFor = $("#useFor").val();// 用途
				var grow = $("#grow").val();// 长
				var wide = $("#wide").val();// 幅
				var tall = $("#tall").val();// 板厚
				var perNum = $("#perNum").val();// 每枚可取数
				var planAmount = $("#planAmount").val();// 可取台数
				var inventory = $("#inventory").val();// 库存
				var jhdata = {
						id : id,
						modelCode : modelCode,
						useFor : useFor,
						grow : grow,
						wide : wide,
						tall : tall,
						perNum : perNum,
						planAmount : planAmount,
						inventory : inventory
					};
				meterResult.push(jhdata);
	    $('#addTable').attr("disabled",true);
		var url = basePath+"/bus/meter/editMeter"
			showLoad();// 加载层
			$.ajax({
				type : "post",
				url : url,
				data : {meterData:JSON.stringify(meterResult)},
				dataType : "json",
				success : function(data) {
					msgPrompt(data.message);
				}
			});
	}
}


function checkInput(){
	var modelCode = $("#modelCode").val();// 部品番号
	var useFor = $("#useFor").val();// 用途
	var grow = $("#grow").val();// 长
	var wide = $("#wide").val();// 幅
	var tall = $("#tall").val();// 板厚
	var perNum = $("#perNum").val();// 每枚可取数
	var planAmount = $("#planAmount").val();// 可取台数
	var inventory = $("#inventory").val();// 库存
	if(modelCode == null || modelCode == undefined || modelCode == ""){
		msgFeedBack("部品番号不能为空","#modelCode");
		return false;
	}
	if(useFor == null || useFor == undefined || useFor == ""){
		msgFeedBack("用途不能为空","#useFor");
		return false;
	}
	if(grow == null || grow == undefined || grow == ""){
		msgFeedBack("送长不能为空","#grow");
		return false;
	}
	if(wide == null || wide == undefined || wide == ""){
		msgFeedBack("宽幅不能为空","#wide");
		return false;
	}
	if(tall == null || tall == undefined || tall == ""){
		msgFeedBack("板厚不能为空","#tall");
		return false;
	}
	if(perNum == null || perNum == undefined || perNum == ""){
		msgFeedBack("每枚可取数不能为空","#perNum");
		return false;
	}
	if(planAmount == null || planAmount == undefined || planAmount == ""){
		msgFeedBack("可取台数不能为空","#planAmount");
		return false;
	}
	if(inventory == null || inventory == undefined || inventory == ""){
		msgFeedBack("入库数量不能为空","#inventory");
		return false;
	}
	return true
}
